package com.kobe.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.kobe.common.annotation.RateLimiter;
import com.kobe.common.annotation.RepeatSubmit;
import com.kobe.task.domain.SysOaTask;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kobe.common.annotation.Log;
import com.kobe.common.core.controller.BaseController;
import com.kobe.common.core.domain.AjaxResult;
import com.kobe.common.enums.BusinessType;
import com.kobe.project.domain.SysOaProject;
import com.kobe.project.service.ISysOaProjectService;
import com.kobe.common.utils.poi.ExcelUtil;
import com.kobe.common.core.page.TableDataInfo;

/**
 * 项目管理Controller
 *
 * @author ruoyi
 * @date 2025-10-18
 */
@RestController
@RequestMapping("/project/project")
public class SysOaProjectController extends BaseController
{
    @Autowired
    private ISysOaProjectService sysOaProjectService;

    /**
     * 查询项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('project:project:list')")
    @RateLimiter(time = 100,count = 50)
    @GetMapping("/list")
    public TableDataInfo list(SysOaProject sysOaProject)
    {
        startPage();
        List<SysOaProject> list = sysOaProjectService.selectSysOaProjectList(sysOaProject);
        return getDataTable(list);
    }
    //查询项目下的任务
    @PreAuthorize("@ss.hasPermi('project:project:list')")
    @GetMapping("listByProjectId")
    public AjaxResult listByProjectId(Long projectId)
    {

        List<SysOaTask> list = sysOaProjectService.listByProjectId(projectId);
        return success(list);
    }

    /**
     * 导出项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('project:project:export')")
    @Log(title = "项目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOaProject sysOaProject)
    {
        List<SysOaProject> list = sysOaProjectService.selectSysOaProjectList(sysOaProject);
        ExcelUtil<SysOaProject> util = new ExcelUtil<SysOaProject>(SysOaProject.class);
        util.exportExcel(response, list, "项目管理数据");
    }

    /**
     * 获取项目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:project:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return success(sysOaProjectService.selectSysOaProjectByProjectId(projectId));
    }

    /**
     * 新增项目管理
     */
    @PreAuthorize("@ss.hasPermi('project:project:add')")
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @RepeatSubmit(interval = 3000, message = "请勿重复添加")
    @PostMapping
    public AjaxResult add(@Valid @RequestBody SysOaProject sysOaProject)
    {
        return toAjax(sysOaProjectService.insertSysOaProject(sysOaProject));
    }

    /**
     * 修改项目管理
     */
    @PreAuthorize("@ss.hasPermi('project:project:edit')")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit(interval = 3000, message = "请勿重复修改")
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody SysOaProject sysOaProject)
    {
        return toAjax(sysOaProjectService.updateSysOaProject(sysOaProject));
    }

    /**
     * 删除项目管理
     */
    @PreAuthorize("@ss.hasPermi('project:project:remove')")
    @Log(title = "项目管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(sysOaProjectService.deleteSysOaProjectByProjectIds(projectIds));
    }
}

